package com.fdb.efp.nls.api.rest;

import com.fdb.basic.framework.core.constant.DataRuleType;
import com.fdb.basic.framework.core.constant.PubConstant;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.nls.service.facade.RateSchemeDetailService;
import com.fdb.efp.nls.service.vo.RateSchemeDetailVO;
import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class RateSchemeDetailController extends AbstractController  {
	
	@Autowired
	@Qualifier("rateSchemeDetailService")
	private RateSchemeDetailService rateSchemeDetailService;
	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;
	
	/**
	 * 列表数据查询
	 */
	@RequestMapping(value="/rate/scheme/details", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<RateSchemeDetailVO>> queryRateSchemeDetailAll(
			@RequestBody RateSchemeDetailVO vo) {		
		List<RateSchemeDetailVO> outputVo = null;
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);
		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = rateSchemeDetailService.queryAllOwner(vo);
			break;
		case CurrOrg:
			outputVo = rateSchemeDetailService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = rateSchemeDetailService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = rateSchemeDetailService.queryAllOwner(vo);
			break;
		}
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 */
	@RequestMapping(value="/rate/scheme/detail/{detailId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<RateSchemeDetailVO> queryByPk(@PathVariable("detailId") String detailId) {		
		RateSchemeDetailVO inVo = new RateSchemeDetailVO();
				inVo.setDetailId(detailId);
		RateSchemeDetailVO outputVo = rateSchemeDetailService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 */
	@RequestMapping(value="/rate/scheme/detail", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody RateSchemeDetailVO inRateSchemeDetailVo) {		
		int outputVo = rateSchemeDetailService.deleteByPk(inRateSchemeDetailVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 */
	@RequestMapping(value="/rate/scheme/detail", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody RateSchemeDetailVO inRateSchemeDetailVo) {
		setUserInfoToVO(inRateSchemeDetailVo);
		int outputVo = rateSchemeDetailService.updateByPk(inRateSchemeDetailVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 */
	@RequestMapping(value="/rate/scheme/detail", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertRateSchemeDetail(@RequestBody RateSchemeDetailVO inRateSchemeDetailVo) {
		setUserInfoToVO(inRateSchemeDetailVo);
		int outputVo = rateSchemeDetailService.insertRateSchemeDetail(inRateSchemeDetailVo);
		return getResponseData(outputVo);
		
	}
}
